package com.zhenhao.xsq.ui.activity.user;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.adapter.door.DoorManageAdapter;
import com.zhenhao.xsq.adapter.user.UserCardAdapter;
import com.zhenhao.xsq.adapter.user.UserListAdapter;
import com.zhenhao.xsq.application.AppConfig;
import com.zhenhao.xsq.base.BaseActivity;
import com.zhenhao.xsq.ui.activity.user.component.DaggerUserCardComponent;
import com.zhenhao.xsq.ui.activity.user.contract.UserCardContract;
import com.zhenhao.xsq.ui.activity.user.module.UserCardModule;
import com.zhenhao.xsq.ui.activity.user.presenter.UserCardPresenter;
import com.zhenhao.xsq.utils.TimeUtil;
import com.zhenhao.xsq.utils.ToastUtil;
import com.zhenhao.xsq.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class UserCardActivity extends BaseActivity implements UserCardContract.View {

    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.bt_commit)
    Button btCommit;
    private String TAG = "UserCardActivity";

    @Inject
    UserCardPresenter mPresenter;

    private UserCardAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_user_card);
        ButterKnife.bind(this);
//        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setToolbarTitle("住户发卡");

        autolayout.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        rootLayout.setBackground(ContextCompat.getDrawable(this, R.mipmap.bg_activity_base));
        toolbarTitle.setTextColor(ContextCompat.getColor(this, R.color.black));
        toolbarMenu.setTextColor(ContextCompat.getColor(this, R.color.color_333333));
        mToolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.mipmap.toolbar_back2));

        initRv();
    }

    private void initRv() {
        UIUtils.configRecycleView(rv, new LinearLayoutManager(this));
        adapter = new UserCardAdapter();
        rv.setAdapter(adapter);

        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                DoorInfo.ListBean.DataBean listBean =
//                        (DoorInfo.ListBean.DataBean) adapter.getData().get(position);
//                switch (view.getId()) {
//                    case R.id.tv_open://开门
//                        ToastUtil.showLong("开门");
//                        if (TimeUtil.isFastClick()) {
////                            DoorInfo.ListBean.DataBean listBean = (DoorInfo.ListBean.DataBean)
////                            adapter.getData()
//// .get(position);
////                            EvenBusMsg evenBusMsg = new EvenBusMsg("HomeService", listBean
////                            .getMac(), "opendoor");
////                            EventBus.getDefault().post(evenBusMsg);
////                            if (listBean.getXdoorType() == 0) {
////                                Map<String, String> map = new HashMap<>();
////                                map.put("xdoorBH", "" + listBean.getXdoorBh());//门禁机编号
////                                mPresenter.kaiMenBle(map);
////                            } else if (listBean.getXdoorType() == 1 || listBean.getXdoorType()
////                            == 3) {
////                                Map<String, String> map = new HashMap<>();
////                                map.put("mac", "" + listBean.getMac());//mac地址
////                                mPresenter.kaiMenFace(map);
////                            }
//                        } else {
//                            ToastUtil.showLong("点击频率过快");
//                        }
//                        break;
//                }
            }
        });

    }

    @Override
    protected void initData() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        adapter.setNewData(list);
    }

    @Override
    protected void setupActivityComponent() {
        DaggerUserCardComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .userCardModule(new UserCardModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    public void setPresenter(UserCardContract.UserCardContractPresenter presenter) {
        mPresenter = (UserCardPresenter) presenter;
    }
}
